﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PPAP.BO;

namespace PPAP.Web.Master
{
    public partial class AttachmenttypeEdit : PageBase
    {
        AttachmentTypeBO bo = new AttachmentTypeBO();
        LogBO lbo = new LogBO();
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!Page.IsPostBack)
            {
                if (Request.QueryString["DID"] != null)
                {
                    LoadDep(Request.QueryString["DID"].ToString());
                }
                //LoadData();
            }
            if (Request.QueryString["deid"] != null)
            {
                dele(Request.QueryString["deid"].ToString());
            }
        }

        private void dele(string id)
        {
            int num = bo.Delete(int.Parse(id));
            lbo.WriteLog(CurrentUser.Id, "Delete AttachmentType");
            if (num > 0)
                AlertMessage("Deleted successful");
            //LoadData();
        }

        //private void LoadData()
        //{
        //    DataSet ds = bo.GetList("");
        //    GridView1.DataSource = ds;
        //    GridView1.DataBind();
        //}

        private void LoadDep(string id)
        {
            Model.AttachmentType d = bo.GetModel(int.Parse(id));
            txtAttachment.Text = d.ATTACHMENTTYPE;
            txtRemark.Text = d.REMARK;
            Button1.Text = "Save";
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Model.AttachmentType d = new Model.AttachmentType();
            int num = 0;
            if (txtAttachment.Text.Trim() == "" || txtRemark.Text.Trim() == "")
            {
                AlertMessage("The text frame not is empty");
                return;
            }
            d.ATTACHMENTTYPE = CheckWord(txtAttachment.Text);
            d.REMARK = CheckWord(txtRemark.Text);
            d.CREATETIME = DateTime.Now;
            d.CREATEDBY = CurrentUser.Id;
            if (Button1.Text == "Add")
            {
                num = bo.Add(d);
                lbo.WriteLog(CurrentUser.Id, "Add AttachmentType:" + d.ATTACHMENTTYPE);
            }
            else
            {
                d.ID = int.Parse(Request.QueryString["DID"].ToString());
                num = bo.Update(d);
                lbo.WriteLog(CurrentUser.Id, "Edit AttachmentType:" + d.ATTACHMENTTYPE);
            }
            if (num > 0)
            {
                txtAttachment.Text = "";
                txtRemark.Text = "";
                Button1.Text = "Add";
                //AlertMessage("Save success");
                AlertReflashOpener("Save success");
            }
            //LoadData();
        }

    }
}